package cn.kimoon.dau_android;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.LinkedList;

import cn.kimoon.dau_android.Model.ModelEngineRoomItem;

/**
 * Created by xiangdong on 2016/11/22.
 */

public class EngineRoomAdapter extends BaseAdapter {
    private LinkedList<ModelEngineRoomItem> mData;
    private Context mContext;

    public EngineRoomAdapter(LinkedList<ModelEngineRoomItem> mData, Context mContext) {
        this.mData = mData;
        this.mContext = mContext;
    }

    public void setData(LinkedList<ModelEngineRoomItem> data) {
        mData = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_list_engine_room, parent, false);
            holder = new ViewHolder();
            holder.leftImageView = (ImageView) convertView.findViewById(R.id.left_img_view);
            holder.contentTextView = (TextView) convertView.findViewById(R.id.content_text_view);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ModelEngineRoomItem item = mData.get(position);
        holder.leftImageView.setImageResource(item.state == 0 ? R.mipmap.engine_nor : R.mipmap.engine_warn);
        holder.contentTextView.setText(item.name);

        return convertView;
    }

    static class ViewHolder {
        ImageView leftImageView;
        TextView contentTextView;
    }
}
